import useUserStore from '@/stores/user'

function isAuth(el, binding) {
    const { authList } = useUserStore()

    const value = binding.value
    if (!value) return
    if (!authList.includes(value)) {
        el.parentNode?.removeChild(el)
    }
}

const mounted = (el, binding) => {
    isAuth(el, binding)
}

const authDirective = {
    mounted,
}

export function setupPermissionDirective(app) {
    app.directive('auth', authDirective)
}

export default authDirective
